{extend name="base" /}
{block name="body"}


<div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
    <div class="layui-card">
        <!--搜索栏-->
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <form action="{:url('admin/auth/index')}" class="layui-form" method="get">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <select name="rolename" lay-filter="lay-select" lay-search>
                            <option value="-1">全部权限</option>
                            <option value="0">管理员</option>
                            <option value="1">超级管理员</option>
                            <option value="2">纠错员</option>
                            <option value="3">采购员</option>
                            <option value="4">推销员</option>
                            <option value="5">运营人员</option>
                            <option value="6">编辑</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-admin ajax-search" lay-submit
                                lay-filter="LAY-user-back-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <!-- 头部操作列 -->
            <div style="padding-bottom: 10px;">
                <a href="{:url('admin/auth/add')}" class="layui-btn ajax-iframe" data-width="410px" data-height="550px">添加菜单</a>
            </div>
            <!--数据表格-->
            <table lay-href="{:url('admin/auth/edit')}" id="tableList" lay-filter="tableList"></table>

            <script type="text/html" id="tableTBTrack">
                <a href="{:url('admin/auth/edit')}?id={{d.id}}" class="layui-btn layui-btn-sm ajax-iframe" data-width="410px" data-height="480px">修改</a>
                <a href="{:url('admin/auth/del')}?id={{d.id}}"
                   class="layui-btn layui-btn-danger layui-btn-sm ajax-delete">删除</a>
            </script>
            <!-- 排序 -->
            <script type="text/html" id="sort">
                <input mid="{{d.id}}" value="{{d.sort}}" style="text-align:center;width: 99%;height: 97%;"
                       class="ajax-change">
            </script>

        </div>
    </div>
</div>


{/block}

{block name="js"}
<script>
    layui.use(['layer', 'form', 'table', 'util'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;

        // 渲染回访表格
        var insTb = table.render({
            elem: '#tableList',
            url: "{:url('admin/auth/index')}",
            page: true,
            height: 'full-200',
            cellMinWidth: 80,
            limit: 5000,
            limits: [10, 50, 100, 500, 1000, 5000, 10000, 50000, 1000000],
            size: 'lg', even: true,
            toolbar: true,
            title: '权限列表',
            totalRow: true,
            cols: [[
                {type: 'numbers', title: '#'},
                {
                    field: 'lefthtml', align: 'left', title: '权限名称'
                    , templet: function (d) {
                        return d.lefthtml + d.title
                    }
                },
                {field: 'name', align: 'left', edit: 'text', style: 'color:#1E9FFF;', title: '权限路径'},
                {field: 'icon', align: 'left', edit: 'text', style: 'color:#1E9FFF;', title: '图标'},
                {field: 'create_time', align: 'center', title: '创建时间', width: 160},
                {field: 'sort', toolbar: '#sort', title: '排序', width: 160},
                {align: 'center', toolbar: '#tableTBTrack', title: '操作', minWidth: 300}
            ]],
            parseData: function (res) { //res 即为原始返回的数据
                console.log(res);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }
        });

        //更新排序
        $(document).on('change', '.ajax-change', function () {
            var id = $(this).attr('mid');
            var sort = $(this).val();

            $.ajax({
                type: 'POST',
                url: '/admin/auth/upSort',
                data: {id: id, sort: sort},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {icon: 1, time: 1500, shade: 0.1}, function (index) {
                            window.location.href = data.url;
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1500, shade: 0.1}, function (index) {
                            layer.close(index);
                        });
                    }

                },
                unSuccess: function (data) {
                    layer.msg("修改失败");
                }
            })
        });


    });


</script>
{/block}